package com.cjjd.c.feature.mine.Integral;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.IntegralBean;
import com.cjjd.c.bean.IntegralItemBean;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/15.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class IntegralFragment extends BaseSwipeRefreshFragment {

    private IntegralBean<IntegralItemBean> listResult;
    private TextView tvIntegral;

    @Override
    public Object getTitleString() {
        return "我的积分";
    }


    @Override
    public void initRightButton(Button rightButton) {
        super.initRightButton(rightButton);
//        rightButton.setVisibility(View.VISIBLE);
//        rightButton.setText("积分说明");
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {

        listResult = (IntegralBean<IntegralItemBean>) response.body().getData();
        tvIntegral.setText(listResult.availableIntegral);
        setDataList(listResult.dataList);

    }

    @Override
    protected void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_header_integral, listBase, false);
        tvIntegral = (TextView) view.findViewById(R.id.tv_integral);

        listBase.addHeaderView(view);
        super.initView();
    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new IntegralAdapter(mContext);
    }

    @Override
    public Call<HttpResult> getCall() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));

        return service.getUserIntegralList(JsonUtils.convertParam("getUserIntegralList", h1));
    }
}
